# -*- coding:utf-8 -*-
# @FileName : app\api\v1\auth\routes.py
# @Time     : 2025/11/28
# @Author   : 天空之城
"""认证模块路由文件

此模块定义认证相关的API路由，如获取当前用户信息等。
"""
from flask import Blueprint
from flask_jwt_extended import jwt_required, get_jwt_identity
from app.utils.response_factory import ResponseFactory
from app.api.v1.users.services import UserService
from app.api.v1.users.schemas import UserSchema

# 创建认证蓝图
auth_bp = Blueprint('auth', __name__)

# 初始化服务和模式
user_service = UserService()
user_schema = UserSchema()


@auth_bp.route('/me', methods=['GET'])
@jwt_required()
def get_current_user():
    """获取当前登录用户信息
    
    Returns:
        JSON格式的用户信息
    """
    current_user_id = int(get_jwt_identity())
    user = user_service.get_user_by_id(current_user_id)
    
    if not user:
        return ResponseFactory.error(msg='User not found', code=404)
    
    return ResponseFactory.success(data=user_schema.dump(user), msg='获取用户信息成功')